//var ruta = window.location.pathname.split("/");
var ruta = '';

function collapseAllRows(table){

   
    var tabla = document.getElementById(table);

    var tbody = tabla.getElementsByTagName('tbody')[0];

    var rows = tbody.getElementsByTagName('tr');

    for (var i = 0; i < rows.length; i++){
        var r = rows[i];

        if(r.id.indexOf("-") >= 0) {
            r.style.display = "none";
        }
    }
}


function toggleRows(elm,table){
 
    var tabla = document.getElementById(table);

    var tbody = tabla.getElementsByTagName('tbody')[0];
    
    var rows = tbody.getElementsByTagName('tr');
    
    elm.src = ruta +"images/nolines_plus.gif";
  
    var newDisplay = "none";
    var thisID = elm.parentNode.parentNode.id + "-";



    for(var i = 0 ; i < rows.length; i++){
        var r = rows[i];
   
        if(matchStart(r.id, thisID, true)){

            if(r.style.display == "none"){
            
                if (document.all)                 
                    newDisplay = "block";
                else newDisplay = "table-row";
                elm.src = ruta+"images/nolines_minus.gif";
            }
            break;
        }
    }

    var matchDirectChildrenOnly = (newDisplay != "none");

    for (var j = 1; j < rows.length; j++) {
        var s = rows[j];

        if (matchStart(s.id, thisID, matchDirectChildrenOnly)) {

            var cell = s.getElementsByTagName("td")[0];
            var nombre = cell.parentNode.id;

            if( validarConoSinImagen(nombre)){
                var img = cell.getElementsByTagName('img')[0];
                img.src = "images/nolines_plus.gif";
            }
     
            s.style.display = newDisplay;
            

        }
    }
}


function matchStart(target, pattern, matchDirectChildrenOnly) {
    var pos = target.indexOf(pattern);

    if (pos != 0) return false;
    if (!matchDirectChildrenOnly) return true;
    if (target.slice(pos + pattern.length, target.length).indexOf("-") >=
        0) return false;
    return true;
}


function validarConoSinImagen(arr){
    var arreglo = arr.split("-")
    if(arreglo.length <= 2){
        return true;
    }
    return false;
}
/*VALIDAR DE PONER EL + EN CASO NO EXISTAN OBJ*/
function ValidarSignoPO(id){
    var   tr = document.getElementById(id);
    alert(tr);
}